package kr.hkit.powerjava.chapter24.work3.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.work3.dao.InterfaceDao;
import kr.hkit.powerjava.chapter24.work3.vo.Student;

public class StudentService extends ServiceItem<Student> {

	public StudentService(InterfaceDao<Student> dao, Scanner sc) {
		super(dao, sc);

	}

	@Override
	public Student inputItemInfo(boolean gubun) {
		System.out.println("학번 성명");
		Student std = new Student(sc.nextInt(), sc.next().trim());
		if(gubun){
			System.out.println("국 영 수");
			std.setKor(sc.nextInt());
			std.setEng(sc.nextInt());
			std.setMath(sc.nextInt());
			
		}
		return std;
	}

	@Override
	public void prnSubMenu() {
		
		System.out.print("1. 이름순 정렬 2. 성적순 정렬 3. 번호순 정렬");
		int res = sc.nextInt();
		switch(res){
			case 1:
				dao.prnItemList(new Comparator<Student>() {
					
					@Override
					public int compare(Student o1, Student o2) {
						
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnItemList(new Comparator<Student>() {

					@Override
					public int compare(Student o1, Student o2) {
						
						return o1.getTotal() - o2.getTotal();
					}
				});
				break;
			default:
				dao.prnItemList(null);
		}
	}
}
